package com.example.home.government.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.example.home.R;
import com.example.home.hospital.activity.IdCardDetail;
import com.example.home.hospital.bean.AllCardBean;
import com.google.gson.Gson;

import java.util.List;

public class PatientIDCardAdapter extends RecyclerView.Adapter<PatientIDCardAdapter.MyHoldy> {
    private Context context;
    private List<AllCardBean.RowsBean> list;

    public PatientIDCardAdapter(Context context, List<AllCardBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card,null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        String sex = list.get(position).getSex();
        if ("1".equals(sex)){
            holder.sex.setText("性别："+"男");
        }else if ("0".equals(sex)){

                holder.sex.setText("性别："+"女");
        }
        holder.name.setText("姓名："+list.get(position).getName());
        holder.address.setText("地址："+list.get(position).getAddress());
        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, IdCardDetail.class);
                Gson gson = new Gson();
                intent.putExtra("carId", gson.toJson(list.get(position)));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private ImageView imgUrl;
        private TextView name;
        private TextView sex;
        private TextView address;
        private RelativeLayout rootView;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            imgUrl = itemView.findViewById(R.id.imgUrl);
            name = itemView.findViewById(R.id.name);
            sex = itemView.findViewById(R.id.sex);
            rootView = itemView.findViewById(R.id.rootView);
            address = itemView.findViewById(R.id.address);
        }
    }
}
